<?php 

require_once 'i_global.php';
require_once 'func_act_edit.php';

if($_REQUEST['action'] == 'register') {
	$errorStr = createUserAct($_REQUEST['activity_id'], $_SESSION['user']['user_id'], $_REQUEST['title'], 
		$_REQUEST['points'], $_REQUEST['targetOrg'], $_REQUEST['targetAmount']);
	if($errorStr > 0) {
		$MESG = "You has successfully registered.";
	} else {
		$MESG = "Error: " . $errorStr;
	}
	
} else if($_REQUEST['action'] == 'complete') {
	$errorStr = completeUserAct($_REQUEST['user_act_id']);
	if($errorStr > 0) {
		$MESG = "Congratulations! Donation will be sent to the charity organition you selected.";
	} else {
		$MESG = "Error: " . $errorStr;
	}
}

$activity_id = $_REQUEST['activity_id'];
if($activity_id > 0) {
	$act = getActivity($activity_id);
}

$userAct = $act != NULL && $_SESSION['user'] != NULL ? getUserAct($activity_id, $_SESSION['user']['user_id']) : NULL;

require_once 'p_header.php';
?>
<div class="span10"><div class="span9">

        <h1><?php echo $act['title']; ?> 
<?php 
if($userAct != NULL) {
	if($userAct['status'] == 'DONE') {
		echo '<span class="label notice">Completed!</span>';
	} else {
		echo '<span class="label success">Registered</span>';
	}	
}
?>
<?php if($MESG != NULL) { ?>
<div class="alert-message info">
  <a class="close" href="#">×</a>
  <p><?php echo $MESG; ?></p>
</div>
<?php }?>
       
        </h1>
        <p>
        <img style="margin: 12px; margin-top: 2px;" src='<?php echo $act['picture'];?>' align="left" />
		<?php echo $act['description'];?>
        
        </p>
        
<?php if(strlen(trim($act['sponser'])) > 0) { ?>        
        <p><img src='<?php echo $act['sponser_img'];?>' align="absmiddle" height="20" hspace="10"/> Sponsered by <?php echo $act['sponser']; ?> </p>
		<p><img src='<?php echo $URL_DIR_IMG; ?>icon_heart.png' align="absmiddle"> For each completed activity, <?php echo $act['sponser']; ?> will donate <b>$<?php echo $act['sponser_amount']; ?></b> to your selected charity organization.</p>
<?php } ?>

		<p>Points: <b><?php echo $act['points'];?></b></p>


<?php if($_SESSION['user'] == NULL) { // not logged in  ?>

<p><a href="login.php" class="btn large primary">Login</a></p>

<?php } else { 
	if($userAct == NULL) { // not registered.
?>

<p>
<form method="post">
<input type="hidden" name="action" value="register" />
<input type="hidden" name='activity_id' value="<?php echo $activity_id; ?>"/>
<input type="hidden" name='title' value="<?php echo $act['title']; ?>"/>
<input type="hidden" name='points' value="<?php echo $act['points']; ?>"/>
<input type="hidden" name='targetAmount' value="<?php echo $act['sponser_amount']; ?>"/>
<input type="submit" class="btn success" name="do" value="I'll do this">
and contribute to <select name="targetOrg" id="targetOrg" style="width: 100px;">
                <option>NKF</option>
                <option>Red Cross</option>
                <option>Heart Foundation</option>
              </select>
</form>
</p>


<?php 		
	} else if($userAct['status'] == 'DONE') { // done.
?>

<p style="font-weight: bold;">You've completed this activity. </p>

<?php } else { // registered, but not done.?>

<p>You are registered for this activity. </p>

<p>
<form method="post">
<input type="hidden" name="action" value="complete" />
<input type="hidden" name='user_act_id' value="<?php echo $userAct['user_act_id']; ?>"/>
<input type="submit" class="btn primary" name="complete" value="I've finished this">
&nbsp;&nbsp;
<input type="checkbox" checked="checked" /> and post to <img src='_IMG/icon_facebook.png' width="24" align="absmiddle">
</form>
</p>
	
<?php
	} 
} // logged in ?>


<h3><i>People who have registered for this activity:</i></h3>
<p>
<a href='user_profile.php' target=_blank><img src='_IMG/person1.jpg' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person2.jpg' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person3.png' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person4.jpg' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person5.jpg' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person6.jpg' width='60' style="border: solid 1px #ccc;"></a>
<a href='user_profile.php' target=_blank><img src='_IMG/person7.jpg' width='60' style="border: solid 1px #ccc;"></a>
</p>

<p align="right" style="margin-top: 32px;"><a href='edit_act.php?activity_id=<?php echo $activity_id; ?>'>Edit this activity</a> (Admin only)</p>

</div></div><!-- end div span9 -->
<?php 
require_once 'p_rightpanel.php';
require_once 'p_footer.php';

?>


